﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;

namespace BusinessStorage
{
    public class Repository
    {
        CloudStorageAccount cloudStorageAccount;
        public Repository()
        {
            cloudStorageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
        }
        public Repository(string connectionstring)
        {
            cloudStorageAccount = CloudStorageAccount.Parse(connectionstring);
        }
        
        public OuSuisJeService GetService()
        {
            OuSuisJeService OuSuisJeService = new OuSuisJeService(cloudStorageAccount.TableEndpoint.ToString(), cloudStorageAccount.Credentials);
            return OuSuisJeService;
        }
        public OuSuisJeBlobs GetBlobContainer()
        {
            CloudBlobClient blobStorage = cloudStorageAccount.CreateCloudBlobClient();  
            CloudBlobContainer container = blobStorage.GetContainerReference("pictures");   
            container.CreateIfNotExist();
            return new OuSuisJeBlobs(container);
        }
        public OuSuisJeBlobs GetBlobContainer(string containername)
        {
            CloudBlobClient blobStorage = cloudStorageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobStorage.GetContainerReference(containername);
            container.CreateIfNotExist();
            container.SetPermissions(new BlobContainerPermissions(){PublicAccess = BlobContainerPublicAccessType.Off});
            return new OuSuisJeBlobs(container);
        }
    }
}
